package com.bawei.home.repos

import com.bawei.common.entity.CommendEntity
import com.bawei.common.entity.VideoEntity
import com.bawei.home.api.HomeServerApi
import com.bawei.home.entity.SimpleTypeEntity
import com.bawei.http.ApiBaseResponse
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject


class HomeRepository @Inject constructor(private val apiServer: HomeServerApi) {

    suspend fun getSimpleType(): ApiBaseResponse<List<SimpleTypeEntity>>{
        return apiServer.getSimpleType()
    }

    suspend fun getRecommendVideo(page:Int, pageSize: Int): ApiBaseResponse<List<VideoEntity>>{
        return apiServer.getRecommendSimpleVideo(page, pageSize)
    }

    suspend fun getVideoByChannelId(channelId:String, page:Int, pageSize: Int): Flow<List<VideoEntity>> {
        return flow {
            var result = apiServer.getSimpleVideoByChannelId(channelId, page, pageSize)
            if(result.code == 0){
                emit(result.data) //发送数据
            }else{
                emit(listOf()) //发送空数据
            }
        }
    }

    suspend fun getVideoCommends(dataType: Int, itemId: String): ApiBaseResponse<List<CommendEntity>>{
        return apiServer.getVideoCommends(dataType, itemId)
    }

}